#include "dominion.h"
#include "testutils.h"
#include <stdio.h>
#include <stdlib.h>

// This unit test was added after it was found via random testing that the
// adventurer card was not discarding itself after being played.

void testAdventurerEffect 
                    (   int args[MAX_PLAYARGS], int cardtypes[MAX_PLAYARGS],
                        carddesc_t desc, struct gameState *g,
                        expectedState_t *expected )
{
    bool thisPlayerNeedsShuffle = args[4] != 0;
    
    pass_printf ("%s: TEST playing %s\n", __func__, desc[0]);
    
    if (thisPlayerNeedsShuffle)
        pass_printf ("\tCurrent player will need shuffle.\n");
    else
        pass_printf ("\tCurrent player won't need shuffle.\n");
    
    int player = g->whoseTurn;
    
    if (thisPlayerNeedsShuffle)
    {
        while (g->deckCount[player])
            g->discard[player][g->discardCount[player]++] = 
                g->deck[player][--g->deckCount[player]];
    }
    
    int expectedCoins = g->coins + 2;
    
    testPlayCard (args[0], args[1], args[2], args[3], g, expected, false);
    
    assert_equal (g->handCount[player], 7, "Verifying player's hand size");
    assert_equal (g->coins, expectedCoins, "verifying number of coins");
    
    testEndTurn (g, expected);
}

int main (int argc, char *argv[])
{
    parse_args (argc, argv);
    
    static playargs_t playargs =
    {
        {arg_handcard,  adventurer, adventurer},
        {arg_num,       0, 0},
        {arg_num,       0, 0},
        {arg_num,       0, 0},
        {arg_num,       0, 1} // thisPlayerNeedsShuffle
    };
    
    run_cardtest (playargs, testAdventurerEffect);
}
